# -*- coding: utf-8 -*-

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class MainWindow(QMainWindow):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent=parent)
        self.setWindowTitle("ToolBar示例")
        self.resize(300, 200)

        layout = QVBoxLayout()
        tb = self.addToolBar("File")
        new = QAction(QIcon("./user_128px.png"), "New", self)
        tb.addAction(new)

        open = QAction(QIcon("./user_128px.png"), "Open", self)
        tb.addAction(open)

        save = QAction(QIcon("./user_128px.png"), "Save", self)
        tb.addAction(save)

        tb.actionTriggered[QAction].connect(self.toolbtn_pressed)
        self.setLayout(layout)

    def toolbtn_pressed(self, a):
        print("pressed tool button is %s" % a.text())


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec())